package sort;

public class Test_1 {
    public static void main(String[] args) {
        int []arr={2,56,24,785,12,85,23,3456,123,856,12,84};
        A.quicksort(arr,0,arr.length-1);
        for(int data:arr){
            System.out.print(data+" ");
        }
    }
}

class A{
    public static void quicksort(int[]arr,int left,int right){
        if(left>=right){
            return;
        }
        int par=partiton(arr,left,right);
        quicksort(arr,left,par-1);
        quicksort(arr,par+1,right);
    }

    public static int partiton(int[]arr,int start,int end){
        int pivot=arr[start];
        int i=start;
        while(start<end){
            while(start<end&&arr[end]>=pivot){
                end--;
            }
            while(start<end&&arr[start]<=pivot){
                start++;
            }
            swap(arr,start,end);
        }
        swap(arr,i,start);
        return start;
    }

    public static void swap(int[] arr,int i,int j){
        int tem=arr[i];
        arr[i]=arr[j];
        arr[j]=tem;
    }
}
